/*
 *
 * Copyright (C) 2014 Ingenic Semiconductor Co.,Ltd
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <config.h>
#include "memory.h"



char *imp_malloc(size_t size)
{
	char *buf = NULL;

    unsigned int ra;
    __asm__ __volatile__ ("move %0, $31" : "=r" (ra));

	buf = malloc(size);

	if (imp_mem_dump){
		printf("[%s] size: %-8d, ptr: 0x%08x, lr:0x%08x\n", __func__ , size, buf, ra);
	}
    //memset(buf, 0, size);
	return buf;
}

char *imp_calloc(size_t nmemb, size_t size)
{
	char *buf = NULL;

    unsigned int ra;
    __asm__ __volatile__ ("move %0, $31" : "=r" (ra));

	buf = calloc(nmemb, size);

	if (imp_mem_dump){
		printf("[%s] size: %-8d, ptr: 0x%08x, lr:0x%08x\n", __func__ , size, buf, ra);
	}
	return buf;
}

char *imp_realloc(void *ptr, size_t size)
{
	char *buf = NULL;

    unsigned int ra;
    __asm__ __volatile__ ("move %0, $31" : "=r" (ra));

	buf = realloc(ptr, size);

	if (imp_mem_dump){
		printf("[%s] size: %-8d, ptr: 0x%08x, lr:0x%08x\n", __func__ , size, buf, ra);
	}
	return buf;
}

void imp_free(void *ptr)
{
	free(ptr);
	if (imp_mem_dump){
		printf("[%s] ptr: %p\n", __func__, ptr);
	}
}
